//
//  taskDetailsCVc.m
//  pacc
//
//  Created by 测试 on 2018/5/30.
//  Copyright © 2018年 测试. All rights reserved.
//
typedef void (^ReturnValueBlock) (BOOL strValue);
#import "shenhetuihuiController.h"
#import "yuepianController.h"
#import "tuihuimodel.h"
#import "shenhetuihuiCell2.h"
#import "mobanController.h"
@interface shenhetuihuiController ()<UITextViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tuihuiyijianConstraint;
@property (weak, nonatomic) IBOutlet UIScrollView *myScrollView;
@property (weak, nonatomic) IBOutlet UIView *textViewSuper;
@property (weak, nonatomic) IBOutlet UIButton *typeBtn;
@property (weak, nonatomic) IBOutlet UITextView *appearanceTV;
@property (weak, nonatomic) IBOutlet UIImageView *upDownImageView;
@property (weak, nonatomic) IBOutlet UITextView *resultTV;
@property (weak, nonatomic) IBOutlet UILabel *shouruLabel;
@property (weak, nonatomic) IBOutlet UIButton *baocunBtn;
@property (weak, nonatomic) IBOutlet UIButton *tijiaoBtn;
@property (weak, nonatomic) IBOutlet UILabel *creatTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *patientNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *patientSexLabel;
@property (weak, nonatomic) IBOutlet UILabel *patientBuweiLabel;
@property (weak, nonatomic) IBOutlet UILabel *patientPhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *hospitalNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *patientAgeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *pacImageView;
@property (weak, nonatomic) IBOutlet UIButton *endEdidBtn;
@property (weak, nonatomic) IBOutlet UIButton *endEdidBtn2;
@property (copy, nonatomic)  NSString *reporID;
@property (weak, nonatomic) IBOutlet UILabel *bianhaoLabel;
@property (weak, nonatomic) IBOutlet UILabel *shenheyijianLabel;
@property (weak, nonatomic) IBOutlet UILabel *OrderNoLabel;
@property(nonatomic,copy)NSString * pacDevice;

@property(nonatomic,copy)NSMutableArray * dataSouce;
@property(nonatomic,copy)NSMutableArray * dataSouce2;

@property (assign, nonatomic)  NSInteger height;

@property(nonatomic,copy)NSArray * mobanArr;


@end

@implementation shenhetuihuiController
- (IBAction)yuepian:(id)sender {
    yuepianController *vc = [yuepianController new];
    vc.yuepianURL = _yuepianURL;
    vc.zid = _zid;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)chaxunyuanyinClick:(UIButton*)sender {
    _myTableview.hidden = !_myTableview.hidden;
    if (_myTableview.hidden) {
        sender.layer.cornerRadius =10;
        self->_tuihuiyijianConstraint.constant = 50;
        [_upDownImageView setImage:[UIImage imageNamed:@"down"]];
    }else{
        sender.layer.cornerRadius =0;
        self->_tuihuiyijianConstraint.constant = _height + 50;
        [_upDownImageView setImage:[UIImage imageNamed:@"up"]];
    }

}
- (IBAction)endEdid:(id)sender {
    [self.view endEditing:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [_myTableview registerNib:[UINib nibWithNibName:@"shenhetuihuiCell2" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
    _myScrollView.backgroundColor = baseBackgroundColor;
    _textViewSuper.backgroundColor = baseBackgroundColor;
    _myTableview.backgroundColor =baseBackgroundColor;
    if (_fromShenhe) {
        self.resultTV.editable = NO;
        self.appearanceTV.editable = NO;
        _isHidden = YES;
    }else{
        self.resultTV.userInteractionEnabled = YES;
        self.appearanceTV.userInteractionEnabled = YES;
        _isHidden = NO;
        [self creatNavRightBtn];
    }
    [self loadData2];
    [self loadData];
    [self loadData3];
    _baocunBtn.hidden = _tijiaoBtn.hidden =_isHidden;
    [_typeBtn setTitle:_odrStatus forState:UIControlStateNormal];
}
#pragma mark --rightBtn--
-(void)creatNavRightBtn{
    UIBarButtonItem * voiceButton= [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"muban_bai"] style:UIBarButtonItemStylePlain target:self action:@selector(goTomoban)];
    [voiceButton setTintColor:[UIColor whiteColor]];
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:voiceButton,nil]];
}
-(void)goTomoban{
    mobanController *vc = [mobanController new];
    vc.jianchasuojianStr = self.appearanceTV.text;
    vc.zhenduanyijianStr = self.resultTV.text;
    NSArray * mobanArr = [[NSUserDefaults standardUserDefaults]objectForKey:@"moban"];
    vc.mubanArr = [mobanArr mutableCopy];
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)getmoban{
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"danyingmanagertemplateselectByParentId"];
    _nameStr =_odrStatus;
    [dic setValue:@"sys" forKey:@"parentId"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:@"订单报告" show:NO success:^(NSDictionary *data) {
        NSDictionary *temdic = [data objectForKey:@"data"];
        if ([temdic isEqual:[NSNull null]]) {
            return ;
        }
        if (temdic) {
            self->_mobanArr = [temdic objectForKey:@"childList"];
            [[NSUserDefaults standardUserDefaults]setValue:self->_mobanArr forKey:@"moban"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }
    } failure:^(NSError *error) {
        
    }];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    
}


-(void)viewWillAppear:(BOOL)animated{
    
    if (my_AppDelegate.backXQ) {
        _appearanceTV.text = my_AppDelegate.jianchasuojianStr;
        _resultTV.text = my_AppDelegate.zhenduanyijianStr;
    }
    my_AppDelegate.backXQ = NO;
    [self getmoban];
    
    
    UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:self.typeBtn.frame byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer=[[CAShapeLayer alloc]init];
    maskLayer.frame=self.typeBtn.bounds;
    maskLayer.path=maskPath.CGPath;
    my_AppDelegate.isLandscape = NO;
    NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
    NSLog(@"orientationUnknown==%@",orientationUnknown);
    [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
    
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    NSLog(@"orientationTarget==%@",orientationTarget);
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}

//是否可以旋转
-(BOOL)shouldAutorotate
{
    return NO;
}

//设置是否隐藏
- (BOOL)prefersStatusBarHidden {
    return NO;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

-(void)loadData2{

    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"orderget"];
    _nameStr =@"订单详情";
    
    [dic setValue:_zid forKey:@"orderId"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:_nameStr show:NO success:^(NSDictionary *data) {
        NSDictionary *temdic = [data objectForKey:@"data"];
        self.shouruLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"price"]];
        self.patientNameLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"patientName"]];
        self.patientSexLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"patientSex"]];
        self.patientPhoneLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"patientPhone"]];
        self.patientAgeLabel.text= [NSString stringWithFormat:@"%@岁",[ZXToolObj getAge:[NSString stringWithFormat:@"%@", [temdic objectForKey:@"patientAge"]]]];
       self.hospitalNameLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"pacFromHos"]];
        self.bianhaoLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"orderDesc"]];
        self.patientBuweiLabel.text = [NSString stringWithFormat:@"%@", [temdic objectForKey:@"pacPart"]];
        NSString *createTime = [NSString stringWithFormat:@"%@",[temdic objectForKey:@"createTime"]];
        
        self.OrderNoLabel.text = [NSString stringWithFormat:@"%@",[temdic objectForKey:@"orderNo"]];
        self.creatTimeLabel.text = [ZXToolObj getTimeStringFormtimestamp:createTime];
        self.pacDevice = [NSString stringWithFormat:@"%@",[temdic objectForKey:@"pacDevice"] ];
        if ([self.pacDevice isEqualToString:@"CT"]) {
            [self.pacImageView setImage:[UIImage imageNamed:@"ct_l"]];
        }else if ([self.pacDevice isEqualToString:@"CR"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"cr_l"]];
        }else if ([self.pacDevice isEqualToString:@"DR"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"dr_l"]];
        }else if ([self.pacDevice isEqualToString:@"DSA"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"dsa_l"]];
        }else if ([self.pacDevice isEqualToString:@"MG"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"mg_l"]];
        }else if ([self.pacDevice isEqualToString:@"MR"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"mr_l"]];
        }else if ([self.pacDevice isEqualToString:@"RF"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"rf_l"]];
        }else if ([self.pacDevice isEqualToString:@"X-Ray"]){
            [self.pacImageView setImage:[UIImage imageNamed:@"X-Ray"]];
        }
        NSArray * arr = [temdic objectForKey:@"orderPac"];
        if (arr.count) {
            NSDictionary *dic = arr[0];
            NSString *urlStr = [dic objectForKey:@"pacUrl"];
            self->_yuepianURL = urlStr;
        }
       
    } failure:^(NSError *error) {
        
    }];
}
-(void)loadData{

    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportgetReportByOrder"];
    _nameStr =_odrStatus;
    [dic setValue:_zid forKey:@"orderId"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:@"订单报告" show:NO success:^(NSDictionary *data) {
        NSDictionary *temdic = [data objectForKey:@"data"];
        if (temdic) {
            self->_reporID = [temdic objectForKey:@"id"];
            NSString *jsonString = [temdic objectForKey:@"report"];
            NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
            NSError *err;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
            NSString *appearance = [dic objectForKey:@"appearance"];
            NSString *result = [dic objectForKey:@"result"];
            self->_resultTV.text = result;
            self->_appearanceTV.text = appearance;
        }
    } failure:^(NSError *error) {
        
    }];
}

-(void)loadData3{
    if (!_dataSouce) {
        _dataSouce=[[NSMutableArray alloc]init];
    }
    if (!_dataSouce2) {
        _dataSouce2=[[NSMutableArray alloc]init];
    }
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportgetOrderReview"];
    _nameStr =_odrStatus;
    [dic setValue:_zid forKey:@"orderId"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:@"审核意见列表" show:NO success:^(NSDictionary *data) {
        NSArray *temArr = [data objectForKey:@"data"];
        self->_height = 0;
        if (![temArr isEqual:[NSNull null]]) {
            if (temArr) {
                for (NSDictionary*temdic in temArr) {
                    tuihuimodel * model = [tuihuimodel new];
                    [model setValuesForKeysWithDictionary:temdic];
                    [self->_dataSouce addObject:model];
                    int height =[model.reviewDesc stringSizeWithMaxSize:CGSizeMake(ScreenWidth, ScreenHeight) withFont:textfont].height+30;
                    self->_height +=height;
                }
                for (NSInteger i = 0; i<self->_dataSouce.count; i++) {
                    NSString * str = [NSString stringWithFormat:@"第%@次审核意见:",[ZXToolObj getStrFromNum:i+1]];
                    [self->_dataSouce2 addObject:str];

                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self->_myTableview reloadData];
                    dispatch_after(1.0, dispatch_get_main_queue(), ^{
                        CGRect frame = self->_myTableview.frame;
                        frame.size.height = self->_height;
                        self->_myTableview.frame = frame;
                        if (self->_height>300) {
                            self->_height = 300;
                        }
                        self->_tuihuiyijianConstraint.constant = self->_height+50;
//                        self.myScrollView.contentSize = CGSizeMake(0, 900);
                        
                        UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:self->_myTableview.bounds byRoundingCorners:UIRectCornerBottomRight|UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)];
                        CAShapeLayer *maskLayer=[[CAShapeLayer alloc]init];
                        maskLayer.frame=self->_myTableview.bounds;
                        maskLayer.path=maskPath.CGPath;
                        self->_myTableview.layer.mask=maskLayer;

                    });
                });
            }
        }
    } failure:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataSouce.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    shenhetuihuiCell2 * cell =[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = _dataSouce[indexPath.row];
    if (_dataSouce2.count>1) {
        cell.contentLabel.text = [NSString stringWithFormat:@"%@%@",_dataSouce2[_dataSouce2.count-1-indexPath.row],cell.contentLabel.text];
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    tuihuimodel * model = _dataSouce[indexPath.row];
    int height =[model.reviewDesc stringSizeWithMaxSize:CGSizeMake(ScreenWidth, ScreenHeight) withFont:textfont].height;
    return height+30;
}
/**
 *  键盘将要显示
 *
 *  @param notification 通知
 */
-(void)keyboardWillShow:(NSNotification *)notification
{
    _endEdidBtn.hidden = NO;
    _endEdidBtn2.hidden = NO;
    //这样就拿到了键盘的位置大小信息frame，然后根据frame进行高度处理之类的信息
    CGRect frame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
//    CGRect scrollViewFrame = self.myScrollView.frame;
//    scrollViewFrame.size.height = self.myScrollView.bounds.size.height + frame.size.height;
//    self.myScrollView.frame = scrollViewFrame;
    NSLog(@"frame显示==%@",NSStringFromCGRect(frame));
    if (_appearanceTV.isFirstResponder) {
        _myScrollView.contentOffset = CGPointMake(0,200);
    }else if (_resultTV.isFirstResponder){
        _myScrollView.contentOffset = CGPointMake(0,360);
    }
    if (ScreenWidth <375) {
        
    }else{
        
    }
    _myScrollView.scrollEnabled = NO;
    
}
/**
 *  键盘将要隐藏
 *
 *  @param notification 通知
 */
-(void)keyboardWillHidden:(NSNotification *)notification
{
    _endEdidBtn.hidden = YES;
    _endEdidBtn2.hidden = YES;
        _myScrollView.scrollEnabled = YES;
    CGRect frame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    NSLog(@"frame隐藏==%@",NSStringFromCGRect(frame));
//    _myScrollView.contentOffset = CGPointMake(0,  0);
}
-(void)viewDidAppear:(BOOL)animated{
    switch (_type) {
        case 0:
            _myScrollView.contentSize = CGSizeMake(0, 667+100);
            //已接单
            _nameStr =@"已接单";
            
            break;
        case 1:
            //已接单
            _myScrollView.contentSize = CGSizeMake(0, 667);

            _nameStr =@"已完工";
            break;
        case 2:
            //已接单
            _nameStr =@"已审核";
            break;
        case 3:
            //已接单
//            [_typeBtn setBackgroundColor:[UIColor redColor]];
            _nameStr =@"未通过";
            break;
        case 4:
            //已接单
            _nameStr =@"已付款";
            break;
        case 5:
            //已接单
            //            [dic setValue:@2 forKey:@"status"];
            _nameStr =@"全部";
            break;
         case 8:
            //
            //            [dic setValue:@2 forKey:@"status"];
            _nameStr =@"待审核";
            [_baocunBtn setTitle:@"退回" forState:UIControlStateNormal];
            [_tijiaoBtn setTitle:@"通过" forState:UIControlStateNormal];

            break;
        default:
            break;
    }
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    return [textField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
-(void)tixing{
    NSLog(@"_resultTV.text===%@------\n_resultTV.text.length====%lu",_resultTV.text,(unsigned long)_resultTV.text.length);
    if (_resultTV.text.length==0) {
        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        return;
    }else if(_appearanceTV.text.length==0){
        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        return;
    }
}
-(void)tixing2{
    if (_resultTV.text.length||_appearanceTV.text.length) {
        
    }else{
        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        return;
    }
}
- (IBAction)preserveClick:(UIButton*)sender {
    [self.view endEditing:YES];
    switch (_type) {
        case 0:case 3:
            //保存报告
            [self baocunbaogao];
            break;
        case 8:
            //保存报告
            [self shenhetuihui];
            break;
        default:
            break;
    }
    
}
-(void)shenhetuihui{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"是否抢单"message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"抢单" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
      
    }];
    
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    
    [self.view endEditing:YES];
    NSDictionary* orderInfo = @{@"appearance":@"12342",
                                @"result":@"果冻"};
    _baocunBtn.enabled = NO;
    // OC对象转JSON
    NSData* json = [NSJSONSerialization dataWithJSONObject:orderInfo options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
    NSLog(@"%@",jsonString);
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportputConfirmedReport"];
    NSString *nameStr =@"审核退回";
    [dic setValue:self.zid forKey:@"orderId"];
    [dic setValue:_reporID forKey:@"reportId"];
    [dic setValue:jsonString forKey:@"reviewDesc"];
    [dic setValue:@0 forKey:@"reviewStatus"];

    [dic setValue:my_AppDelegate.token forKey:@"token"];
    
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:nameStr show:YES success:^(NSDictionary *data) {
        self->_baocunBtn.enabled = YES;
        NSString *status = [NSString stringWithFormat:@"%@", [data objectForKey:@"status"]];
        if ([status isEqualToString:@"200"]) {
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    } failure:^(NSError *error) {
        self->_baocunBtn.enabled = YES;
    }];
}
-(void)baocunbaogao{
    if (_resultTV.text.length==0&&_appearanceTV.text.length==0) {
        [SVProgressHUD showErrorWithStatus:@"报告内容不能都为空"];
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        return;
    }else if(_appearanceTV.text.length==0){
//        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
//        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
//        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
//        return;
    }
    [self.view endEditing:YES];
    NSDictionary* orderInfo = @{@"appearance":_appearanceTV.text,
                                @"result":_resultTV.text};
    _tijiaoBtn.enabled = NO;
    // OC对象转JSON
    NSData* json = [NSJSONSerialization dataWithJSONObject:orderInfo options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
    NSLog(@"%@",jsonString);
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportsaveReport"];
    NSString *nameStr =@"保存报告";
    [dic setValue:self.zid forKey:@"orderId"];
    [dic setValue:jsonString forKey:@"report"];
    [dic setValue:_reporID forKey:@"id"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:nameStr show:NO success:^(NSDictionary *data) {
        self->_tijiaoBtn.enabled = YES;
        NSString *repoidStr = [data objectForKey:@"data"];
        NSString *msg = [data objectForKey:@"msg"];
        NSString *status = [NSString stringWithFormat:@"%@", [data objectForKey:@"status"]];
    if ([status isEqualToString:@"200"]) {
        [SVProgressHUD showSuccessWithStatus:msg];
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
    }
        self->_reporID = repoidStr;
//        NSLog(@"arr=%@",arr);
    } failure:^(NSError *error) {
        self->_tijiaoBtn.enabled = YES;
    }];
}
- (IBAction)postClick:(UIButton*)sender {
    [self.view endEditing:YES];
    switch (_type) {
        case 0:case 3:
            
            [self tijiaobaogao];
            break;
        case 8:
            [self shenhetongguo];
            break;
        default:
            break;
    }
}
-(void)tijiaobaogao{
    if (_resultTV.text.length==0) {
        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        return;
    }else if(_appearanceTV.text.length==0){
        [SVProgressHUD showErrorWithStatus:@"报告内容不能为空"];
        dispatch_after(1.0, dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
        return;
    }
    [self.view endEditing:YES];
    NSDictionary* orderInfo = @{@"appearance":_appearanceTV.text,
                                @"result":_resultTV.text};
    _tijiaoBtn.enabled = NO;
    // OC对象转JSON
    NSData* json = [NSJSONSerialization dataWithJSONObject:orderInfo options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
    NSLog(@"%@",jsonString);
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportputReport"];
    NSString *nameStr =@"提交报告";
    [dic setValue:_zid forKey:@"orderId"];
    [dic setValue:jsonString forKey:@"report"];
    [dic setValue:_reporID forKey:@"id"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:nameStr show:NO success:^(NSDictionary *data) {
        NSString *status = [NSString stringWithFormat:@"%@", [data objectForKey:@"status"]];
        if ([status isEqualToString:@"200"]) {
            BOOL inputString = YES;
            
            __weak typeof(self) weakself = self;
            
            if (weakself.returnValueBlock) {
                //将自己的值传出去，完成传值
                weakself.returnValueBlock(inputString);
            }
            NSString *msg = [data objectForKey:@"msg"];

            [SVProgressHUD showSuccessWithStatus:msg];
            [SVProgressHUD setBackgroundColor:RGB(85, 85, 85)];
            [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
        
        self->_tijiaoBtn.enabled = YES;
    } failure:^(NSError *error) {
        self->_tijiaoBtn.enabled = YES;
    }];
}
-(void)shenhetongguo{
    _tijiaoBtn.enabled = NO;
//    NSDictionary* orderInfo = @{@"appearance":@"12342",
//                                @"result":@"果冻"};
//    // OC对象转JSON
//    NSData* json = [NSJSONSerialization dataWithJSONObject:orderInfo options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
//    NSLog(@"%@",jsonString);
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    NSString *str =[NSString stringWithFormat:@"reportputConfirmedReport"];
    NSString *nameStr =@"审核通过";
    [dic setValue:self.zid forKey:@"orderId"];
    [dic setValue:_reporID forKey:@"reportId"];
    [dic setValue:@1 forKey:@"reviewStatus"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    
    [NetWorking startPOSTRequestWithUrl:str parameters:dic logMes:nameStr show:YES success:^(NSDictionary *data) {
        self->_tijiaoBtn.enabled = YES;
        NSString *status = [NSString stringWithFormat:@"%@", [data objectForKey:@"status"]];
        if ([status isEqualToString:@"200"]) {
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    } failure:^(NSError *error) {
        self->_tijiaoBtn.enabled = YES;
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
